import request from '@/config/axios'
import type { TplUpdateVo, TplCreateVo, TplQueryDto, TplCreateDirVo } from './types'

// 查询左边树
export const getTplTreeApi = async () => {
  return await request.get({ url: '/cms/tpl/tree' })
}

// 查询列表
export const getTplListApi = async (params?: TplQueryDto) => {
  return await request.get({ url: '/cms/tpl/list', params })
}

//查询模型匹配的模板
export const getChannelTpl = async (pc: boolean, modelId?: number) => {
  return await request.get({
    url: '/cms/tpl/getChannelTpl?modelId=' + modelId + '&pc=' + pc
  })
}
//查询栏目列表所有模板
export const getChannelListAllTpls = async (pc: boolean) => {
  return await request.get({
    url: '/cms/tpl/getChannelTpl?isDetail=false&pc=' + pc
  })
}
//查询内容详情所有模板
export const getContentDetailAllTpls = async (pc: boolean) => {
  return await request.get({
    url: '/cms/tpl/getChannelTpl?isDetail=true&pc=' + pc
  })
}
//查询首页模板
export const getIndexTpl = async (pc: boolean) => {
  return await request.get({
    url: '/cms/tpl/getIndexTpl?pc=' + pc
  })
}

export const getSiteTplSolutionApi = async () => {
  return await request.get({ url: '/cms/tpl/getSolutions' })
}
// 新增模板
export const createTplApi = async (data: TplCreateVo) => {
  return await request.post({ url: '/cms/tpl/save', data })
}

// 修改模板
export const updateTplApi = async (data: TplUpdateVo) => {
  return await request.post({ url: '/cms/tpl/update', data })
}

// 删除模板资源
export const deleteTplApi = async (names: String) => {
  return await request.post({ url: '/cms/tpl/delete?names=' + names })
}

// 查询详情
export const getTplDetail = async (filename: String) => {
  return await request.get({ url: '/cms/tpl/detail?name=' + filename })
}

//导出模板
export const exportApi = (solution: String) => {
  return request.download({
    url: '/cms/tpl/export?solution=' + solution
  })
}

//新建目录
export const createDirApi = async (data: TplCreateDirVo) => {
  return await request.post({ url: '/cms/tpl/dir', data })
}

// 查询版本列表
export const getTplVersionListApi = async (tplPath) => {
  return await request.get({ url: '/cms/tpl-version/page', tplPath })
}
// 删除版本
export const deleteTplVersionApi = async (id: number) => {
  return await request.delete({ url: '/cms/tpl-version/delete?id=' + id })
}
// 查询版本详情
export const getTplVersionApi = async (id: number) => {
  return await request.get({ url: '/cms/tpl-version/get?id=' + id })
}
// 恢复当前版本
export const restoreTplApi = async (id: number) => {
  return await request.post({ url: '/cms/tpl/restore?id=' + id })
}
